/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.glodon.ggzy.sso.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 *
 * @author yuanweilin
 */
public class TimeUtil {

	//获取当前时间：yyyy-MM-dd HH:mm:ss
	public static String getNowTime() {
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simple.format(new Date());
	}
	
	public static String getTime(Date date) {
		if(date == null)return "";
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return simple.format(date);
	}
	public static String getDate(Date date) {
		if(date == null)return "";
		SimpleDateFormat simple = new SimpleDateFormat("yyyy-MM-dd");
		return simple.format(date);
	}

	public static void main(String args[]) {
		System.out.println("Time:" + getNowTime());
	}
	


    public static String DateToCN(Date date) {   
    	
    	   if (null == date || "".equals(date)) {   
               return null;   
           }   
           String[] CN = { "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九" };  
           
           Calendar calendar = Calendar.getInstance();   
           calendar.setTime(date);   
           StringBuffer cn = new StringBuffer();   
           String year = String.valueOf(calendar.get(Calendar.YEAR));   
           for (int i = 0; i < year.length(); i++) {   
               cn.append(CN[year.charAt(i) - 48]);   
           }   
           cn.append("年");   
           int mon = calendar.get(Calendar.MONTH) + 1;   
           if (mon < 10) {   
               cn.append(CN[mon]);   
           } else if (mon < 20) {   
               if (mon == 10) {   
                   cn.append("十");   
               } else {   
                   cn.append("十").append(CN[mon % 10]);   
               }   
           }   
           cn.append("月");   
           int day = calendar.get(Calendar.DAY_OF_MONTH);   
           if (day < 10) {   
               cn.append(CN[day]);   
           } else if (day < 20) {   
               if (day == 10) {   
                   cn.append("十");   
               } else {   
                   cn.append("十").append(CN[day % 10]);   
               }   
           } else if (day < 30) {   
               if (day == 20) {   
                   cn.append("二十");   
               } else {   
                   cn.append("二十").append(CN[day % 10]);   
               }   
           } else {   
               cn.append("三十").append(CN[day % 10]);   
           }   
           cn.append("日");   
           
           return cn.toString();   
    }
}
